window.addEvent('domready', function() {
    $('usersearch').addEvent('keyup', function() {
        var search_value = $('usersearch').getProperty('value');
        var url = $('baseurl').getProperty('value') + '/index.php?option=com_docario&controller=group&task=getJUsersJSON&format=component';
        var gid = $('id').getProperty('value');
        
        if (search_value.length > 3) {
            new Ajax(url, {
                method: 'post',
                data: {
                    'search': search_value,
                    'cid': gid
                },
                onSuccess: function(data) {
                    $('searchresults').innerHTML = data;
                    $('searchresults').removeClass('hidden');
                    $$('.canceler').removeClass('hidden');
                }
            }).request();
        } else {
            $('searchresults').addClass('hidden');
            $$('.canceler').removeClass('hidden');
        }
    });
    
    $$('.canceler').addEvent('click', function() {
        $('searchresults').addClass('hidden');
        $$('.canceler').addClass('hidden');
    });
    
});
